#ifndef _GP_H
#define _GP_H

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <string>
#include <map>
#include <vector>
using std::string;
using std::map;
using std::vector;

//#define DEBUG

#define IP_ADDR_LEN 20
#define BUFF_MAXSIZE 4096

#define RECV_PORT 1120

#define HB_PORT 1121
#define HB_SEC	1
#define HB_TIMEOUT 3

#define RSMESS_PORT 1122
#define SERVICE_PORT 1123
#define FILE_PORT 1124
#define FTP_PORT 1125
#define ADMIN_PORT 1126
#define MAXLOAD 5

enum CGNodeStatus {
    OFFLINE = -1,
    ONLINE,
    STAT_INIT,
    STAT_NORMAL,
    STAT_ADJUST,
    STAT_UPDATE,
    STAT_FAULT,
    STAT_RECONSTRUCT,
    STAT_RECONFIG,
    STAT_PAUSE
};

enum MessageType {
    HEART_BEAT,
    NODE_INIT,
    NODE_PAUSE,
    NODE_WORK,
    NODE_ADD,
    NODE_DEL,
    RECOVER_ASKACK,
    RECOVER_ACK,
    RECOVER_IMAGE,
    RECOVER_RECONSTRUCT,
    RECOVER_RECONFIG,

    CLI_REQ,
    FORWARD_REQ,
    FIND_SUCCESS,
    //FIND_BUSY
    FIND_FAIL,
    ANSWER_REQ,
    SERVICE_REQ,
    CANT_FIND,
    //SEND_REQ,
    SEND_PLEASE,
    //SEND_WAIT,
    SOURCE_REQ,
    LOAD_REQ,
    ANSWER_LOAD,
    ADD_RS,
    DELETE_RS,
    ADD_COMPLETE,
    DELETE_COMPLETE,
    WAIT_REQ,
    DO_TASK
};

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#endif
